package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.BaseDto;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void add(BaseDto baseDto) {
        Bed bean = BeanUtil.toBean(baseDto, Bed.class);
        log.info("新加的床位：{}",bean);
        bean.setCreateTime(LocalDateTime.now());
        bean.setCreateBy(1L);
        bean.setUpdateTime(LocalDateTime.now());
        bean.setUpdateBy(2L);
        bean.setBedStatus(0);
        bedMapper.addBed(bean);

    }

    @Override
    public BedVo Getbyid(Long bedid) {
//        Bed bed =bedMapper.Getbyid(bedid);
//        BedVo bedVo = BeanUtil.toBean(bed, BedVo.class);
        Bed bed =bedMapper.Getbyid(bedid);
        BedVo bedVo = BeanUtil.toBean(bed, BedVo.class);
        return bedVo;
    }

    @Override
    public void update(BedDto bedDto) {
        Bed bed = BeanUtil.toBean(bedDto, Bed.class);
        log.info("修改的放假：{}",bed);
        bed.setUpdateTime(LocalDateTime.now());
        bed.setUpdateBy(1L);
        bedMapper. update(bed);


    }

    @Override
    public void deletebyid(Long id) {
        bedMapper.deletebyid(id);




    }

}







